/**********************************************
/ file : constellation_mapping.sc
/ Author : Jungmin Park
/ Date : 4/25/2011 
/ Specification Model of Constellation mapping 
***********************************************/
#include <stdio.h>
import "c_double_handshake";

behavior Constellation_mapping (i_receiver IR1, i_receiver IR2, i_sender IS1, i_sender IS2)
{
  long mask = 0x0000000F;
	long temp = 0;
	long temp1 = 0;
	long temp2 = 0;
	int i;
	float v1, v2;
	
  void main (void)
 {
  IR1.receive (&temp1, sizeof(temp1));
  IR2.receive (&temp2, sizeof(temp1));
  
  for (i=0; i<16; i++) 
	{	
	  if ( i >= 8) 
	    temp = temp2 & mask;
	  else 
	    temp = temp1 & mask;
	  switch( temp ) 
	  {
     case 0:
       v1 = 1;  
		   v2 = 1; 
		   break; 
	   case 1:
		   v1 = 1;
		   v2 = 3;
		   break;
	   case 2:
		   v1 = 3;  
		   v2 = 1; 
		   break; 
	   case 3:
		   v1 = 3;
		   v2 = 3;
		   break; 
     case 4:
		   v1 = 1;  
		   v2 = -1; 
		   break; 
	   case 5:
		   v1 = 1;
		   v2 = -3;
		   break;
	   case 6:
		   v1 = 3;  
		   v2 = -1; 
		   break; 
	   case 7:
		   v1 = 3;
		   v2 = -3;
		   break; 
     case 8:
		   v1 = -1;  
		   v2 = 1; 
		   break; 
	   case 9:
		   v1 = -1;
		   v2 = 3;
		   break;
	   case 10:
		   v1 = -3;  
		   v2 = 1; 
		   break; 
	   case 11:
		   v1 = -3;
		   v2 = 3;
		   break; 
     case 12:
		   v1 = -1;  
		   v2 = -1; 
		   break; 
	   case 13:
		   v1 = -1;
		   v2 = -3;
		   break;
	   case 14:
		   v1 = -3;  
		   v2 = -1; 
		   break; 
	   case 15:
		   v1 = -3;
		   v2 = -3;
		   break; 
	   }
	   IS1.send (&v1, sizeof(v1));
	   IS2.send (&v2, sizeof(v1));
	   if ( i >= 8) 
	    temp2 >>= 4;
	   else 
	    temp1 >>= 4;
	 }
	}
};